<script setup lang="ts">
import { useRouter } from 'vue-router';
import { reactive, ref, watch, computed, effect } from 'vue';

const router = useRouter();

const courseList = ref([
  {
    id: 1,
    title: 'c语言程序设计',
    tag: '软件学院',
    img: '/courselist/c语言程序设计.webp',
    rate: 3.5,
    teacher: '罗永胜',
    people: 99,
    content: '本课程将用最典型的实例和通俗的讲解为你讲授程序设计的思想',
  },
  {
    id: 2,
    title: 'java核心技术概论',
    tag: '软件学院',
    img: '/courselist/java核心技术概论.webp',
    rate: 4.5,
    teacher: '江导',
    people: 100,
    content: 'java是一门程序设计语言，长期位居编程语言排行榜TIOBE的首位',
  },
  {
    id: 3,
    title: 'python金融分析',
    tag: '软件学院',
    img: '/courselist/python金融分析.webp',
    rate: 2,
    teacher: '张凯',
    people: 120,
    content: '简洁却强大、简单却专业，它是当今世界最受欢迎的编程语言!',
  },
  {
    id: 4,
    title: '高等数学',
    tag: '人文学院',
    img: '/courselist/高等数学.webp',
    rate: 3,
    teacher: '岑苑君 康永强',
    people: 70,
    content: '高等数学是各高校本科生必修的一门重要基础课',
  },
  {
    id: 5,
    title: '交际英语',
    tag: '人文学院',
    img: '/courselist/交际英语.webp',
    rate: 2.5,
    teacher: '吴晓燕',
    people: 100,
    content: '以职业需求为导向，着重培养你的实际英语运用能力！',
  },
  {
    id: 6,
    title: 'web前端开发技术',
    tag: '软件学院',
    img: '/courselist/web前端开发技术.webp',
    rate: 1,
    teacher: '罗永胜 何小民',
    people: 50,
    content: 'web前端开发是创建网页或APP界面呈现给用户的过程',
  },
  {
    id: 7,
    title: '数据科学与应用',
    tag: '软件学院',
    img: '/courselist/数据科学与应用.webp',
    rate: 4.5,
    teacher: '宋海生',
    people: 10,
    content: '本课程以大数据、人工智能时代为背景，采用项目制的学习方式',
  },
  {
    id: 8,
    title: '数据挖掘',
    tag: '软件学院',
    img: '/courselist/数据挖掘.webp',
    rate: 4,
    teacher: '宋海生',
    people: 40,
    content: '数据挖掘作为大数据分析技术主要组成部分',
  },
  {
    id: 9,
    title: '数学建模',
    tag: '人文学院',
    img: '/courselist/数学建模.webp',
    rate: 4,
    teacher: '邱仰聪',
    people: 60,
    content: '欢迎热爱数学建模，挑战数学建模竞赛的同学来学习该课程',
  },
  {
    id: 10,
    title: '网页设计基础',
    tag: '软件学院',
    img: '/courselist/网页设计基础.webp',
    rate: 2,
    teacher: '罗永胜',
    people: 100,
    content: '以职业需求为导向，着重培养你的实际英语运用能力！',
  },
  {
    id: 11,
    title: '哲学导论',
    tag: '人文学院',
    img: '/courselist/哲学导论.webp',
    rate: 3,
    teacher: '黄子文',
    people: 49,
    content: '高校专业学生必修的专业基础课',
  },
  {
    id: 12,
    title: '前端开发',
    tag: '软件学院',
    img: '/courselist/前端开发.webp',
    rate: 4,
    teacher: '李改',
    people: 100,
    content: '前端开发技术课程由浅及深介绍了HTML语言及CSS技术相关知识',
  },
]);

const changefn = (e: any) => {
  courseList.value = courseList.value.filter(item => item.title.indexOf(e.value) !== -1);
};
</script>

<template>
  <div class="container">
    <div class="search">
      <SearchBar @handler="changefn"></SearchBar>
    </div>
    <div class="courseList">
      <div class="item animate__animated animate__zoomIn animate__delay-0.9s" v-for="item in courseList" :key="item.id">
        <div class="item_header">
          <img :src="item.img" alt="" />
          <div id="tag">{{ item.tag }}</div>
        </div>
        <div class="item_body">
          <div class="title">{{ item.title }}</div>
          <div class="teacher">{{ item.teacher }}</div>
          <div style="font-size: 10px">{{ item.people }}人已经参与</div>
          <div class="content">{{ item.content }}</div>
          <div class="btn">
            <div class="box">
              <div class="rate">
                <el-rate v-model="item.rate" disabled show-score text-color="#ff9900" score-template="{value} 分" />
              </div>
            </div>
            <router-link class="btn" :to="{ path: '/details/' + item.id, query: item }">加入课程</router-link>
          </div>
        </div>
      </div>
    </div>
    <div class="pagination">
      <el-pagination background layout="prev, pager, next" :total="100" />
    </div>
  </div>
</template>

<style scoped lang="scss">
.container {
  width: 90%;
  height: 100%;
  margin: auto;

  .pagination {
    position: absolute;
    right: 9vw;
    bottom: 10px;
  }
}

:deep(.el-pagination.is-background .el-pager li:not(.is-disabled).is-active) {
  background-color: $theme-color;
}

// .search {}

.courseList {
  width: 100%;
  // height: 450px;
  height: 90%;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  overflow: auto;

  .item {
    width: 180px;
    height: 280px;
    border-radius: 5px;
    background-color: #fff;
    margin: 15px 10px;
    overflow: hidden;
    font-size: 12px;
    transition: all 0.2s linear;

    &_header {
      width: 100%;
      height: 126px;
      position: relative;
      padding: 10px;
      img {
        border-radius: 5px;
        width: 100%;
        height: 100%;
      }

      #tag {
        position: absolute;
        background-color: #567e7a;
        background-color: #fff;
        // background-color: #42c9ca;
        // color: #ffffff;
        color: $blue-color;
        border-radius: 5px;
        opacity: 0.7;
        top: 15px;
        left: 15px;
        padding: 4px;
      }
    }

    &_body {
      display: flex;
      flex-direction: column;
      align-items: center;

      .title {
        margin-top: 5px;
        font-size: 14px;
        color: #333;
        font-weight: bold;
      }

      .teacher {
        margin: 6px 0;
        color: #666;
      }

      .content {
        margin-top: 5px;
        width: 80%;
        height: 35px;
        overflow: hidden; //超出包裹器隐藏
        text-overflow: ellipsis; //显示省略符号来代表被修剪的文本。
      }

      .box {
        position: absolute;
        bottom: 40px;

        .rate {
          width: 170px;
          border-radius: 5px;
          position: relative;
          background-color: $bgcolor;
          display: none;
        }

        .rate::before {
          /*下三角*/
          content: '';
          position: absolute;
          bottom: -7px;
          /*调整块大小时需调节三角位置*/
          left: 80px;
          border-top: 8px solid $bgcolor;
          border-left: 8px solid transparent;
          border-right: 8px solid transparent;
        }
      }

      .btn:hover .rate {
        display: block;
      }

      .btn {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100px;
        height: 30px;
        line-height: 30px;
        border-radius: 5px;
        background-color: $theme-color;
        color: #fff;
      }
    }
  }

  .item:hover {
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
  }
}

:deep(.el-rate.is-disabled .el-rate__item) {
  color: #d0bbab;
}
</style>
